//
//  TJUserPrivacyController.m
//  Teleport
//
//  Created by hc-101 on 2020/6/23.
//  Copyright © 2020 xtjun. All rights reserved.
//

#import "TJUserPrivacyController.h"
#import <TTTAttributedLabel.h>


@interface TJUserPrivacyController()<TTTAttributedLabelDelegate, UIScrollViewDelegate>

@property (weak, nonatomic) UIView *mainContentView;
@property (weak, nonatomic) UIScrollView *mainView;

@end

@implementation TJUserPrivacyController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.navigationBar.lineView.hidden = YES;
    
       CGFloat scrollViewH = KScreenHeight - KNavBarHight;
       UIScrollView *placeholderView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, KNavBarHight, KScreenWidth, scrollViewH)];
       placeholderView.showsHorizontalScrollIndicator = NO;
       placeholderView.showsVerticalScrollIndicator = NO;
       placeholderView.bounces = NO;
       placeholderView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
       [self.view addSubview:placeholderView];
       CGSize contentSize = CGSizeMake(KScreenWidth, scrollViewH);
       placeholderView.contentSize = contentSize;
       
       UIScrollView *mainView = [[UIScrollView alloc] initWithFrame:placeholderView.bounds];
       mainView.showsHorizontalScrollIndicator = NO;
       mainView.showsVerticalScrollIndicator = NO;
       mainView.delegate = self;
       mainView.contentSize = contentSize;
       [placeholderView addSubview:mainView];
       
       UIView *mainContentView = [UIView tj_addToView:mainView];
       [mainContentView mas_makeConstraints:^(MASConstraintMaker *make) {
           make.edges.offset(0);
           make.width.offset(KScreenWidth);
           make.height.offset(scrollViewH);
       }];
       
       _mainView = mainView;
       _mainContentView = mainContentView;
       
 
    TTTAttributedLabel *label = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
    [mainContentView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(16);
        make.right.offset(-16);
        make.top.offset(0);
    }];
    label.delegate = self;
    label.font = [UIFont systemFontOfSize:12];
    label.textColor = UIColor_Hex(0x666666);
    label.lineBreakMode = NSLineBreakByWordWrapping;
    label.numberOfLines = 0;
    
    label.linkAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                            [NSNumber numberWithBool:NO],(NSString *)kCTUnderlineStyleAttributeName,nil];
    label.activeLinkAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                  [UIColor darkGrayColor],(NSString *)kCTForegroundColorAttributeName,nil];
    NSString *text = @"Teleport有权审查和监督用户对teleport的使用。如果用户在使用Teleport时违反了上述任何规定，则teleport或其授权人员有权要求用户纠正或直接采取某些必要措施（包括但不限于更改或删除用户发布的内容，暂停或终止用户对Teleport的使用）以减少由用户行为引起的不当行为对成功的影响".localizedString;
 
    [label setText:text afterInheritingLabelAttributesAndConfiguringWithBlock:^ NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) {
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.lineSpacing = 8;
        paragraphStyle.paragraphSpacing = 4;
        paragraphStyle.alignment = NSTextAlignmentLeft;
        [mutableAttributedString addAttribute:(NSString *)kCTParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, text.length)];

        return mutableAttributedString;
    }];
    
       
       [self.view setNeedsLayout];
       [self.view layoutIfNeeded];
       
       [self.mainContentView layoutIfNeeded];
       [self.mainContentView setNeedsLayout];
       
       contentSize = CGSizeMake(KScreenWidth, CGRectGetMaxY(label.frame) + 20);
       self.mainView.contentSize = contentSize;
       [self.mainContentView mas_updateConstraints:^(MASConstraintMaker *make) {
           make.height.offset(contentSize.height);
       }];
       
 
}
 

@end
